package 结构型模式.装饰器;

/**
 * @ClassNamePanCakeTest
 * @Description
 * @Author
 * @Date2021/12/16 11:45
 **/
public class PanCakeTest {

    public static void main(String[] args) {
        PanCake panCake = new PanCake();
        System.out.println(panCake.getMessage() + "---" + panCake.getPrice());

        // 加一个鸡蛋
        EggDecorator eggDecorator = new EggDecorator(panCake);
        System.out.println(eggDecorator.getMessage() + "---" + eggDecorator.getPrice());
        //再加一个鸡蛋
        EggDecorator eggDecorator1 = new EggDecorator(eggDecorator);
        System.out.println(eggDecorator1.getMessage() + "---" + eggDecorator1.getPrice());
        // 加一根香肠
        SausageDecorator sausageDecorator = new SausageDecorator(eggDecorator1);
        System.out.println(sausageDecorator.getMessage() + "---" + sausageDecorator.getPrice());
    }
}

// 煎饼类
class PanCake {
    String getMessage() {
        return "煎饼";
    }

    int getPrice() {
        return 5;
    }
}

// 装饰器
abstract class Decorator extends PanCake {
    private PanCake panCake;

    public Decorator(PanCake panCake) {
        this.panCake = panCake;
    }

    @Override
    String getMessage() {
        return this.panCake.getMessage();
    }

    @Override
    int getPrice() {
        return this.panCake.getPrice();
    }
}


// 鸡蛋煎饼装饰器
class EggDecorator extends Decorator {
    public EggDecorator(PanCake panCake) {
        super(panCake);
    }

    @Override
    String getMessage() {
        return super.getMessage() + "1个鸡蛋";
    }

    @Override
    public int getPrice() {
        return super.getPrice() + 1;
    }
}

// 香肠装饰器
class SausageDecorator extends Decorator {
    public SausageDecorator(PanCake panCake) {
        super(panCake);
    }

    @Override
    String getMessage() {
        return super.getMessage() + "1根香肠";
    }

    @Override
    public int getPrice() {
        return super.getPrice() + 2;
    }
}
